package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.AddAllAlhProductBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.AddAllAlhProductCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;
/**
*一健添加全部在售商品到安利会
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AddAllAlhProduct{
	private static AddAllAlhProductBean AddAllAlhProductBean;
	private static AddAllAlhProductCall AddAllAlhProductCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("一健添加全部在售商品到安利会");
	}

	@Before
	public void caseUp() {
		AddAllAlhProductBean=new AddAllAlhProductBean();
		AddAllAlhProductCall=new AddAllAlhProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(AddAllAlhProductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddAllAlhProduct_001() {
		Logger.start(true,"信息正确,一键添加成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			AddAllAlhProductBean.setUserId(sellerId);
			AddAllAlhProductCall.setData(AddAllAlhProductBean);
			AddAllAlhProductCall.callService();			
			Logger.verifyEquals("200", AddAllAlhProductCall.getJsonObject().get("Code").getAsString(), "验证Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_AddAllAlhProduct_002() {
		Logger.start(true,"部分商品未上架,一键添加成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			addProdReq.getProduct().setOnSaleType(2);
			addProdReq.getProduct().setAutoRefresh(false);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			
			AddSellerProductRequest addProdReq1 = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV3.AddSellerProduct(addProdReq1);
			
			AddAllAlhProductBean.setUserId(sellerId);
			AddAllAlhProductCall.setData(AddAllAlhProductBean);
			AddAllAlhProductCall.callService();			
			
			Logger.verifyEquals("200", AddAllAlhProductCall.getJsonObject().get("Code").getAsString(), "验证Code");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_AddAllAlhProduct_003() {
		Logger.start(true,"用户id错误,一键添加失败");
		try {
			AddAllAlhProductBean.setUserId(123123);
			AddAllAlhProductCall.setData(AddAllAlhProductBean);
			AddAllAlhProductCall.callService();			
			Logger.verifyEquals("200", AddAllAlhProductCall.getJsonObject().get("Code").getAsString(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_AddAllAlhProduct_004() {
		Logger.start(true,"商品库存为0,一键添加失败");
		try {
			
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			
			new YmtCatalogsIWapper().updatestocknumByProductID(0,productId);
			AddAllAlhProductBean.setUserId(sellerId);
			AddAllAlhProductCall.setData(AddAllAlhProductBean);
			AddAllAlhProductCall.callService();			
			Logger.verifyEquals("200", AddAllAlhProductCall.getJsonObject().get("Code").getAsString(), "验证Code");
			
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}